package com.czxy.dao;

import com.czxy.domain.Guest;
import com.czxy.domain.GuestVo;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/2/6
 */
@org.apache.ibatis.annotations.Mapper
public interface GuestDao extends Mapper<Guest> {
    @Select("select * from guest_management where state = 1")
    @Results({
            @Result(property = "uid",column = "uid"),
            @Result(property = "user",column = "uid",one = @One(select = "com.czxy.dao.UserDao.selectByPrimaryKeyFn"))
    })
    List<Guest> findAllGuestWYYD(GuestVo guestVo);

    @Select("select * from guest_management where state = 2")
    @Results({
            @Result(property = "uid",column = "uid"),
            @Result(property = "user",column = "uid",one = @One(select = "com.czxy.dao.UserDao.selectByPrimaryKeyFn"))
    })
    List<Guest> findAllGuestWTGSH(GuestVo guestVo);

    @Select("select * from guest_management where state = 0")
    @Results({
            @Result(property = "uid",column = "uid"),
            @Result(property = "user",column = "uid",one = @One(select = "com.czxy.dao.UserDao.selectByPrimaryKeyFn"))
    })
    List<Guest> findAllGuestKX();

    @Select("<script> select * from guest_management " +
            "<where>" +
            "<if test=\" roomname != null and roomname != '' \"> and roomname = #{roomname} </if>" +
            "<if test=\" state != null and state != '' or state == 0 \"> and state = #{state}</if>" +
            "</where> order by roomnumber " +
            "</script>")
    @Results({
            @Result(property = "uid",column = "uid"),
            @Result(property = "user",column = "uid",one = @One(select = "com.czxy.dao.UserDao.selectByPrimaryKeyFn"))
    })
    List<Guest> findAllGuest(GuestVo guestVo);

    @Select("select * from guest_management where roomname = #{roomname}")
    List<Guest> findOneByName(@Param("roomname") String roomname);

    @Select("select * from guest_management")
    @Results({
            @Result(property = "uid",column = "uid"),
            @Result(property = "user",column = "uid",one = @One(select = "com.czxy.dao.UserDao.selectByPrimaryKeyFn"))
    })
    List<Guest> findAllGuestBook();

    @Select("select * from guest_management where rid = #{rid}")
    @Results({
            @Result(property = "uid",column = "uid"),
            @Result(property = "user",column = "uid",one = @One(select = "com.czxy.dao.UserDao.selectByPrimaryKeyFn"))
    })
    Guest findOneGuestByRid(@Param("rid") Integer rid);

    @Select("SELECT * FROM guest_management WHERE starttime > #{s} AND starttime <= #{s1}")
    List<Guest> amountofbusiness(@Param("s") String s,@Param("s1") String s1);
}
